/**
 *Project: jh-framework
 *File: cn.xkshow.framework.spider.demo.Tester.java 
 *Author: admin@xkshow.cn with the copyrite
 ****************************************************************
 *   VERSION       DATE            BY       CHANGE/COMMENT
 * --------------------------------------------------------------
 *    1.0        2013-4-19        xkshow.cn         create
 ****************************************************************
 *note:
 ***************************************************************/ 
package cn.xkshow.commons.spider.demo;

import java.util.List;

import cn.xkshow.commons.spider.baseIface.UrlListI;
import cn.xkshow.commons.spider.dPattern.UrlListFactory;
import cn.xkshow.commons.spider.model.BlogXk;
import cn.xkshow.commons.spider.model.Sina;
import cn.xkshow.commons.spider.CollBuilder;
import cn.xkshow.commons.spider.CollDirector;
import cn.xkshow.commons.spider.Collector;
import cn.xkshow.commons.spider.Universal;

public class Tester {

	private static void sina(){
		//Static factory design pattern
		UrlListI ulst = UrlListFactory.getFactory("SinaUList", "http://roll.edu.sina.com.cn/lm/gk/gkrx/kaoshi/index_2.shtml", "gb2312");
		List lst = ulst.getListUrl();
		for (int i = 0; i < lst.size(); i++) {
			//Builder design pattern
			CollBuilder cb = new Collector(new Sina(lst.get(i).toString(), "gb2312"));
			CollDirector cd = new CollDirector();
			cd.makeCollector(cb);
			Universal universal = cb.getCollector();
			
			System.out.println(" Title:"+universal.getTitle());
			System.out.println(" Date:"+universal.getDate());
			System.out.println(" From:"+universal.getSource());
			System.out.println(" Txts:"+universal.getContent());
			System.out.println("-----------------");
		}
		System.out.println("Total:"+lst.size());
	}
	
	private static void blogXk(){
		//Static factory design pattern
		UrlListI ulst = UrlListFactory.getFactory("BlogXkUList", "http://www.xkshow.cn/index.php/archives/category/technicality/page/1", "UTF-8");
		List lst = ulst.getListUrl();
		for (int i = 0; i < lst.size(); i++) {
			//Builder design pattern	
			CollBuilder cb = new Collector(new BlogXk(lst.get(i).toString(), "UTF-8"));
			CollDirector cd = new CollDirector();			
			cd.makeCollector(cb);			
			Universal universal = cb.getCollector();
			
			System.out.println(" Title:"+universal.getTitle());
			System.out.println(" Date:"+universal.getDate());
			System.out.println(" From:"+universal.getSource());
			System.out.println(" Txts:"+universal.getContent());
			System.out.println("------------------------");
		}
		System.out.println("Total:"+lst.size());
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Tester.sina();
	}

}
